home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / PIL / GimpPaletteFile.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  1KB  |  46 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import re
  5. import string
  6.  
  7. class GimpPaletteFile:
  8.     rawmode = 'RGB'
  9.     
  10.     def __init__(self, fp):
  11.         self.palette = map((lambda i: chr(i) * 3), range(256))
  12.         if fp.readline()[:12] != 'GIMP Palette':
  13.             raise SyntaxError, 'not a GIMP palette file'
  14.         
  15.         i = 0
  16.         while i <= 255:
  17.             s = fp.readline()
  18.             if not s:
  19.                 break
  20.             
  21.             if re.match('\\w+:|#', s):
  22.                 continue
  23.             
  24.             if len(s) > 100:
  25.                 raise SyntaxError, 'bad palette file'
  26.             
  27.             v = tuple(map(int, string.split(s)[:3]))
  28.             if len(v) != 3:
  29.                 raise ValueError, 'bad palette entry'
  30.             
  31.             if i <= i:
  32.                 pass
  33.             elif i <= 255:
  34.                 self.palette[i] = chr(v[0]) + chr(v[1]) + chr(v[2])
  35.             
  36.             i = i + 1
  37.             continue
  38.             0
  39.         self.palette = string.join(self.palette, '')
  40.  
  41.     
  42.     def getpalette(self):
  43.         return (self.palette, self.rawmode)
  44.  
  45.  
  46.